package com.ljf.interestingmaps.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.WindowManager;

import com.ljf.interestingmaps.R;


public class LoadingDialog extends Dialog {

	private static LoadingDialog instance;
	private static Context preContext;

	public LoadingDialog(Context context, int theme) {
		super(context, theme);
	}

	public LoadingDialog(Context context ) {
		super(context, R.style.Theme_Dialog_Common);
		fullScreen(context);
		setContentView(R.layout.dialog_loading);
		preContext = context;
	}

	public static LoadingDialog getInstance(Context context){
		if(instance == null || preContext != context){
			instance = new LoadingDialog(context);
		}

		return  instance;
	}

	private void fullScreen(Context context){
		// 将对话框的大小按屏幕大小的百分比设置
		WindowManager windowManager = ((Activity)context).getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		WindowManager.LayoutParams lp = getWindow().getAttributes();
		lp.width = (int)(display.getWidth()); //设置宽度
		getWindow().setAttributes(lp);
	}

	public static void show(Context context){
		getInstance(context).show();
	}

	public static void dissmiss(Context context){
		getInstance(context).dismiss();
	}
}
